package com.jeff.huawei.practice;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class First1 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int M = scanner.nextInt();

        // 如果M的值不在1到100之间，输出错误信息
        if (M <= 1 || M >= 100) {
            System.out.println("ERROR!");
        }
        else {
            // 创建一个存储100个Person的环形链表
            List<Person> list = new ArrayList<>();
            for (int i = 1; i <= 100; i++) {
                list.add(new Person(i));
            }
            // 将链表首位相连
            for (int i = 0; i < 99; i++) {
                list.get(i).next = list.get(i + 1);
            }
            list.get(99).next = list.getFirst();

            // 准备报数 让最后一位充作起始坐标
            Person current = list.getLast();
            while (list.size() >= M) {
                for (int i = 1; i < M; i++) {
                    // 移动到下一个人
                    current = current.next;
                }
                //删除掉报数为M的人
                list.remove(current.next);
                //淘汰第M个报数的人
                current.next = current.next.next;
            }

            for (int i = 0; i < list.size(); i++) {
                System.out.print(list.get(i).selfNumber);
                if (i != list.size() - 1) {
                    System.out.print(",");
                }
            }
        }
    }

    // 定义一个 Person 类，包含编号和是否被淘汰的属性
    static class Person {
        int selfNumber;
        Person next;

        public Person(int number) {
            this.selfNumber = number;
        }
    }

}
